home *** CD-ROM | disk | FTP | other *** search
- Path: isonews.bbn.hp.com!hpbblb!news
- From: Matthias Dittrich <matti>
- Newsgroups: comp.lang.c
- Subject: Re: Help! Initializing a C string
- Date: 22 Mar 1996 12:28:44 GMT
- Organization: Hewlett-Packard Co.
- Message-ID: <4iu6ds$c74@hpbblb.bbn.hp.com>
- References: <1996Mar18.095842.2435@condor>
- NNTP-Posting-Host: trabant.bbn.hp.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.07 9000/712)
- X-URL: news:1996Mar18.095842.2435@condor
-
- mdipilla@condor.navsses.navy.mil wrote:
- >to whom is all C' knowing...
- >
- > I have a string which is formulating by several lines from an input file.
- >The approach we hae taken is to do a strncpy of the first line and then
- >strncat of each additional line.
- >
- > When the string is formed we need to null it out so we can read the next
- >string in.
- >
- > The problem we are having is that if we set the string to "\0"
- >we
- >
- > 1. Overwrite the first line (strcpy)
- > 2. However the 2nd, 3rd, 4th, etch lines of the string are concatenated
- >after the initial string that wwas written.
- >
- > how do you INIitialze the variable of the string so it is clear and you
- >do not have this overwrite problem.
- >..
- If you are using strncpy to copy the first line, the string has no '\0' at
- the end. You can put it there using:
- str[n] = '\0';
-
- Hope this was your problem,
- Matthias
-
-